use anyhow::{Error};
use clap::Parser;

use rcli::{Opts, process_csv, gen_pass_word, Subcommand, base64_process, process_sign, process_verify, TextSubCommand};


// use TextSubCommand ;
fn main() -> anyhow::Result<(), Error> {
    let opts = Opts::parse();
    match opts.cmd {
        Subcommand::Csv(opt) => {
            let path = match opt.output {
                Some(aa) => aa,
                None => format!("output.{}", opt.format).to_string(),
            };
            process_csv(&opt.input.as_str(), path.as_str(), opt.format)
        }

        Subcommand::GenPass(opt) => {
            let passwd = gen_pass_word(opt.lowercase, opt.uppercase, opt.number, opt.symbol, opt.length);

            println!("passwd is {}", passwd.unwrap());
        }
        Subcommand::Base64(opt) => {
            let out = base64_process(opt.base_type, opt.format, opt.input)?;

            println!("out is {}", out)
        }

        Subcommand::text(opts) => {
            // println!("opts is {:?}", opts);
            match opts {
                TextSubCommand::Sign(opt) => {
                    let out = process_sign(&opt.input, &opt.key, opt.format);
                    println!("签名是: {:?}", out?);
                }
                TextSubCommand::Verify(opt) => {
                    let out = process_verify(&opt.input, &opt.key, &opt.sign, opt.format);
                    println!("签名验证结果是: {:?}", out?);
                }
            }
        }

        _ => {}
    }

    Ok(())
}




